<!DOCTYPE html>
<html lang="zh">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>测试</title>
    <link
      href="https://unpkg.com/daisyui@5.0.4/daisyui.css"
      rel="stylesheet"
      type="text/css"
    />
    <script src="https://unpkg.com/@tailwindcss/browser@4"></script>
  </head>
  <body class="p-4">
    <h1>
      <span class="text-4xl font-bold">自检信息</span>
      <button id="recheck" class="btn btn-ghost btn-sm">刷新</button>
    </h1>
    <ul>
      <li><span class="font-bold">dir:</span> <span id="dir"></span></li>
      <li>
        <span class="font-bold">document_dir:</span>
        <span id="document_dir"></span>
      </li>
      <br />
      <li>
        <span class="font-bold">settings:</span>
        <span id="settings"></span>
      </li>
      <li>
        <span class="font-bold">morning:</span>
        <span id="morning"></span>
      </li>
      <li>
        <span class="font-bold">evening:</span>
        <span id="evening"></span>
      </li>
      <li><span class="font-bold">now:</span> <span id="now"></span></li>
      <br />
      <li>
        <span class="font-bold">morning.start &lt;= now:</span>
        <span id="morning.start_now"></span>
      </li>
      <li>
        <span class="font-bold">now &lt;= morning.end:</span>
        <span id="now_morning.end"></span>
      </li>
      <li>
        <span class="font-bold">morning:</span>
        <span id="is_morning"></span>
      </li>
      <br />
      <li>
        <span class="font-bold">evening.start &lt;= now:</span>
        <span id="evening.start_now"></span>
      </li>
      <li>
        <span class="font-bold">now &lt;= evening.end:</span>
        <span id="now_evening.end"></span>
      </li>
      <li>
        <span class="font-bold">evening:</span>
        <span id="is_evening"></span>
      </li>
      <br />
      <li><span class="font-bold">url:</span> <span id="url"></span></li>
    </ul>

    <script>
      const invoke = window.__TAURI__.core.invoke;

      function selfCheck() {
        for (const id of [
          "dir",
          "document_dir",
          "settings",
          "morning",
          "evening",
          "now",
          "morning.start_now",
          "now_morning.end",
          "is_morning",
          "evening.start_now",
          "now_evening.end",
          "is_evening",
          "url",
        ]) {
          invoke("get_data", { name: id }).then((data) => {
            document.getElementById(id).innerText = data;
            document
              .getElementById(id)
              .classList.remove(
                "text-red-600",
                "text-yellow-600",
                "text-green-600"
              );
            if (data.includes("Failed")) {
              document.getElementById(id).classList.add("text-red-600");
              document.getElementById("self-check").open = true;
            }
            if (id == "url" && data.includes("Exit"))
              document.getElementById(id).classList.add("text-yellow-600");
            if (id.includes("is_") && data.includes("true"))
              document.getElementById(id).classList.add("text-green-600");
          });
        }
      }
      selfCheck();
      document.getElementById("recheck").addEventListener("click", selfCheck);
    </script>
  </body>
</html>
